﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Web.UI;

namespace Acms.AcmsControls.ContentControls.Admin 
{
    public class FlashVideoAdminDisplay : BaseAdminDisplay<FlashVideoContentControlProperties>
    {

        protected override string GetCssClass
        {
            get { return "flashVideo"; }
        }

        Acms.WebControls.FlashControl flash = new Acms.WebControls.FlashControl();

        public override void PropertiesLoaded(FlashVideoContentControlProperties properties)
        {
            if (properties != null)
            {
                HasFile = properties.HasResource();
                flash.Variables["videoUrl"] = Page.ResolveUrl((RenderFile.GetUrl(Properties.ResourceId, Page)));
            }
            else
            {
                HasFile = false;
            }

        }

        protected override void CreateChildControls()
        {
            flash.WMode = Acms.WebControls.FlashControl.WModes.Transparent;
            flash.FlashFileUrl = Page.ResolveUrl("~/Flash/FlashVideo.swf");
            flash.Variables["videoSkinUrlStr"] = Page.ResolveUrl("~/Flash/custom.swf");
            flash.Width = flash.Height = 500;
            this.Controls.Add(flash);
            base.CreateChildControls();
        }

        private bool HasFile { get; set; }
        protected override object SaveViewState()
        {
            ViewState["HasFile"] = HasFile;
            return base.SaveViewState();
        }

        protected override void LoadViewState(object savedState)
        {
            base.LoadViewState(savedState);
            HasFile = (bool)ViewState["HasFile"];
        }

        protected override void RenderContents(System.Web.UI.HtmlTextWriter writer)
        {
            if (HasFile)
            {
                flash.RenderControl(writer);
            }
            else
            {
                writer.Write("No flash video file has been uploaded");
            }
        }
    }
}
